#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

# lsattr - Testcases
mkdir dir && cd dir && touch file
chattr +A file &>/dev/null

_p=$PWD
_b="-------------"
_A="-------A-----"

testing "file" "lsattr file" "$_A file\n" "" ""
testing "file_path" "lsattr $_p/file" "$_A $_p/file\n" "" ""
testing "-R file" "lsattr -R file" "$_A file\n" "" ""
testing "-R file_path" "lsattr -R $_p/file" "$_A $_p/file\n" "" ""
testing "-a file" "lsattr -a file" "$_A file\n" "" ""
testing "-a file_path" "lsattr -a $_p/file" "$_A $_p/file\n" "" ""
testing "-d ." "lsattr -d ." "$_b .\n" "" ""
testing "-d dir_path" "lsattr -d $_p" "$_b $_p\n" "" ""
testing "-d file" "lsattr -d file" "$_A file\n" "" ""
testing "-d file_path" "lsattr -d $_p/file" "$_A $_p/file\n" "" ""
sp_44="                                            "
testing "-l file" "lsattr -l file" "file  $sp_44 No_Atime\n" "" ""
_v="12345"
testing "-v file" "chattr -v $_v * && lsattr -v file" \
  "$_v $_A file\n" "" ""
testing "-v file_path" "chattr -v $_v * && lsattr -v $_p/file" \
  "$_v $_A $_p/file\n" "" ""
testing "-Radlv file1 file2" "chattr -v $_v * &&
   lsattr -Radlv file input" \
  "$_v file  $sp_44 No_Atime\n$_v input $sp_44 ---\n" "" ""

# Cleanup
chattr -AacDdijsStTu file && cd ..
rm -rf dir
